import constant from "../../constant"
import storage from '../../utils/storage'
// import { watchSwitchLang } from '../../utils/i18n'
export default {
    namespaced: true,
    state: () => ({
        sidebarOpened: true,
        language: storage.getItem(constant.LANG) || 'zh',
        tagsViewList: storage.getItem(constant.TAGS_VIEW) || []
    }),
    mutations: {
        triggerSidebarOpened(state) {
            state.sidebarOpened = !state.sidebarOpened
        },
        setLanguage(state, lang) {
            state.language = lang
            storage.setItem(constant.LANG, lang)
        },
        addTagsViewList(state, tag) {
            console.log(tag);
            const isFind = state.tagsViewList.find(item => {
                return item.path === tag.path
            })
            if (!isFind) {
                state.tagsViewList.push(tag)
                storage.setItem(constant.TAGS_VIEW, state.tagsViewList)
            }
        },
        changeTagsView(state, { index, tag }) {
            state.tagsViewList[index] = tag
            storage.setItem(constant.TAGS_VIEW, state.tagsViewList)
        },
        removeTagsView(state, payload) {
            if (payload.type == 'index') {
                state.tagsViewList.splice(payload.index, 1)
            } else if (payload.type == 'right') {
                // console.log(payload.index + 1);
                // console.log(state.tagsViewList.length);
                // console.log(state.tagsViewList.length - (payload.index + 1));
                state.tagsViewList.splice(payload.index + 1, state.tagsViewList.length - (payload.index + 1))
            } else if (payload.type == 'other') {
                state.tagsViewList.splice(0, payload.index);
                state.tagsViewList.splice(1, state.tagsViewList.length - 1);
            }
            storage.setItem(constant.TAGS_VIEW, state.tagsViewList)
        },
    },
    actions: {
        
    },
}